<template>
	<view>
		<top imgSrc="../../static/img/Logo-ERoad-文字版-1.png"></top>

		<view class="title">
			<view class="titleContent" v-for="item in titleContent" :key="item.id" @tap="handleTitle(item.id)"
				:class="[titleActive === item.id?'active':'']"><text>{{item.name}}</text>
				<image src="../../static/img/icon-选中-03.png" mode="widthFix" v-if="titleActive === item.id"></image>
			</view>
		</view>

		<view class="order" v-for="item in orderInf" :key="item.orderId" @tap="toOrderDetail(item)">
			<view class="orderIdBox">
				<text>订单号：{{item.orderId}}</text>
				<text :style="{background:item.background}">{{item.orderState}}</text>
			</view>

			<view class="fareInf">
				<view class="fareBox"></view>
				<view class="orderTime">
					<text>{{item.orderDay}}</text>
					<text>{{item.orderTime}}</text>
				</view>
				<view class="site">
					<view class="depart">
						<text>{{item.orderDepart}}</text>
						<text>{{item.orderLocation}}</text>
					</view>
					<view class="plate">
						<text>{{item.plate}}</text>
						<image src="../../static/img/icon-directivity-01.png" mode="widthFix"></image>
					</view>

					<view class="destination">
						<text>{{item.orderDestination}}</text>
					</view>
				</view>


				<view class="pricePayBox" v-if="item.orderState=='未支付'">
					<text>需支付</text>
					<text class="pricePay">￥{{item.orderPrice}}</text>
					<view class="pay">前往支付</view>
				</view>

				<view class="priceBox" v-else>
					<text class="price">￥{{item.orderPrice}}</text>
					<text>车票当日当次有效</text>
				</view>


			</view>
		</view>



	</view>


</template>

<script>
	import top from "../../components/top/top.vue"
	export default {
		data() {
			return {
				titleContent: [{
						id: 0,
						name: "全部"
					},
					{
						id: 1,
						name: "未支付"
					},
					{
						id: 2,
						name: "待出行"
					},
					{
						id: 3,
						name: "已完成"
					},
				],
				titleActive: 0,
				orderInf: []
			}
		},
		components: {
			top
		},
		onShow() {
			this.shuaxing()
		},
		onLoad() {
			
		},
		methods: {
			// 选项卡
			handleTitle(id) {

				this.titleActive = id;
				this.shuaxing()
			},
			// 跳转订单详情
			toOrderDetail(item) {
				uni.navigateTo({
					url: "/pages/orderDetail/orderDetail?orderDetail=" + encodeURIComponent(JSON.stringify(item))
				})
			},
			// 获取数据
			async shuaxing() {
				const res = await this.$myRequest({
					url: "/order/listAllOrder",
					data: {
						userId: 3
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
					},
				})
				if (res.data) {
					this.orderInf = res.data
					if (this.titleActive != 0) {
						this.orderInf = this.orderInf.filter(item =>
							item.orderState === this.titleContent[this.titleActive].name
						)
					}
				}
			}
		},



	}
</script>

<style lang="scss">
	.title {
		display: flex;
		align-items: center;
		height: 104rpx;
		text-align: center;
		font-family: PingFang SC, PingFang SC;
		font-size: 40rpx;
		font-weight: 500;
		color: #545454;

		.titleContent {
			width: 25%;
			height: 104rpx;

			text {
				display: block;
			}

			image {
				float: right;
				width: 54rpx;
				margin-right: 56rpx;
			}
		}

		.active {
			font-weight: bold;
		}


	}

	.order {
		width: 686rpx;
		box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(235, 106, 88, 0.14);
		border-radius: 24rpx;
		margin: 36rpx auto;

		.orderIdBox {
			height: 52rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #333333;
			border-bottom: 2rpx solid #d9d9d9;

			text:nth-child(1) {
				margin-left: 64rpx;
			}

			text:nth-child(2) {
				display: block;
				width: 72rpx;
				height: 32rpx;
				background: #b7b7b7;
				border-radius: 24rpx;
				margin-right: 36rpx;
				font-size: 16rpx;
				color: #fff;
				text-align: center;
				line-height: 32rpx;
			}

		}

		.fareInf {
			display: flex;
			height: 198rpx;
			position: relative;

			.fareBox {
				width: 44rpx;
				height: 44rpx;
				border-radius: 44rpx;
				box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(235, 106, 88, 0.14);
				background: #EB6A58;
				opacity: .14;
				margin-left: 30rpx;
				margin-top: 50rpx;
			}

			.orderTime {
				display: flex;
				flex-direction: column;
				font-size: 24rpx;
				font-family: Inter, Inter;
				font-weight: 400;
				color: #333333;
				margin-top: 44rpx;
				margin-left: 8rpx;

				text:nth-child(2) {
					font-weight: bold;
					color: #000000;
					font-size: 36rpx;
				}
			}

			.site {
				display: flex;
				margin-top: 36rpx;
				margin-left: 48rpx;
				height: 198rpx;

				.depart {
					display: flex;
					flex-direction: column;

					text:nth-child(1) {
						font-size: 32rpx;
						font-weight: 400;
						color: #000000;
					}

					text:nth-child(2) {
						display: block;
						margin-top: 12rpx;
						width: 124rpx;
						height: 28rpx;
						background: #F7C269;
						font-size: 16rpx;
						font-weight: 500;
						color: #FFFFFF;
						text-align: center;
						line-height: 28rpx;
					}
				}

				.plate {
					display: flex;
					flex-direction: column;
					font-size: 16rpx;
					text-align: center;
					position: relative;
					color: #545454;
					width: 162rpx;
					height: 10rpx;
					margin-top: 20rpx;

					image {
						width: 162rpx;
					}

					text {
						position: absolute;
						left: 42rpx;
						bottom: 4rpx;

					}
				}

				.destination {
					font-size: 32rpx;
					font-weight: 400;
					color: #000000;
					margin-left: 16rpx;
				}
			}

			.priceBox {
				position: absolute;
				bottom: 18rpx;
				right: 49rpx;
				display: flex;
				flex-direction: column;

				.price {
					font-size: 16rpx;
					font-weight: bold;
					color: #EB6A58;
				}

				text:nth-child(2) {
					font-size: 12rpx;
					color: #545454;
				}
			}

			.pricePayBox {
				display: flex;
				position: absolute;
				justify-content: center;
				align-items: center;
				bottom: 18rpx;
				right: 32rpx;

				text:nth-child(1) {
					font-size: 16rpx;
					color: #545454;
				}

				.pricePay {
					font-size: 16rpx;
					font-weight: bold;
					color: #EB6A58;
				}

				.pay {
					width: 152rpx;
					height: 48rpx;
					border-radius: 48rpx;
					border: 1rpx solid #EB6A58;
					color: #EB6A58;
					font-size: 24rpx;
					text-align: center;
					line-height: 48rpx;
					margin-left: 20rpx;
				}
			}
		}
	}
</style>
